namespace AltNetUK.Models
{
    using System;
    using System.Globalization;
    using System.Net.Mail;
    using System.Text;

    public sealed class AttendeeEmail
    {
        private Registration _registration;

        public AttendeeEmail(Registration registration)
        {
            this.Registration = registration;
        }

        public Registration Registration
        {
            get
            {
                return this._registration;
            }

            set
            {
                if (null == value)
                {
                    throw new ArgumentNullException("value");
                }

                this._registration = value;
            }
        }

        public void Send()
        {

            MailMessage email = new MailMessage();
            email.To.Add(new MailAddress(this.Registration.Email, this.Registration.Name));
            email.From = new MailAddress("no-reply@altnetuk.com", "Alt.Net UK Conference");
            email.IsBodyHtml = false;

            email.Subject = "Alt.Net UK Conference 2009 Registration";

            #region Body

            StringBuilder body = new StringBuilder();

            body.AppendLine(this.Registration.Name + ",");
            body.AppendLine(string.Empty);
            body.AppendLine("Thank you for registering to attend the Alt.Net UK 2009 Conference.");
            body.AppendLine(string.Empty);
            body.AppendLine("You have requested attendance at the following events:");
            if (this.Registration.AltNetBeers)
            {
                body.AppendLine("\tAlt.Net Beers on Friday 31 July 2009");
            }

            if (this.Registration.OpenSpaceCoding)
            {
                body.AppendLine("\tSaturday 1 August 2009");
            }

            if (this.Registration.AltNetConference)
            {
                body.AppendLine("\tSunday 2 August 2009");
            }

            body.AppendLine(string.Empty);
            body.AppendLine("On behalf of the organisers");
            body.AppendLine("http://altnetuk.com/");

            email.Body = body.ToString();

            #endregion

            new SmtpClient().Send(email);
        }
    }
}